home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / manual-p / man_db-2.000 / man_db-2 / man_db-2.3.10 / lib / rename.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-04  |  1.1 KB  |  43 lines

  1. /* rename -- rename a file
  2.    Copyright (C) 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of the libiberty library.
  5. Libiberty is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9.  
  10. Libiberty is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with libiberty; see the file COPYING.LIB.  If
  17. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  18. Cambridge, MA 02139, USA.  */
  19.  
  20. /* Rename a file.  */
  21.  
  22. #include <errno.h>
  23.  
  24. #ifndef STDC_HEADERS
  25. extern int errno;
  26. #endif
  27.  
  28. int
  29. rename (zfrom, zto)
  30.      char *zfrom;
  31.      char *zto;
  32. {
  33.   if (link (zfrom, zto) < 0)
  34.     {
  35.       if (errno != EEXIST)
  36.     return -1;
  37.       if (unlink (zto) < 0
  38.       || link (zfrom, zto) < 0)
  39.     return -1;
  40.     }
  41.   return unlink (zfrom);
  42. }
  43.